<?php
namespace app\alipay\controller;

use tp5_lib\common\controller\BaseController;
use tp5_lib\alipay\utility\Alipay;

/**
 * @property Alipay $alipay
 * @property \AopClient $client
 */
class SdkTestController extends BaseController
{
    public function __construct()
    {
        $this->alipay=new Alipay();
        $this->client=$this->alipay->client;
    }
    /*
    Array
    (
        [app_id] => 2016080800193517
        [source] => alipay_wallet
        [scope] => auth_base,auth_user
        [auth_code] => d9669c2b0af84bbfaec108598734XX93
    )
     */
    public function auth()
    {
        $url=$this->alipay->getOAuthUrl("http://www.airbaba.cn/custom/wechat_cb.php");
        $this->redirect($url);
    }
    /*
    stdClass Object ( 
        [alipay_system_oauth_token_response] => stdClass Object ( 
            [access_token] => composeB7a9a4f43981044e8aa1e34bfee099X93 
            [alipay_user_id] => 2088102173187930 
            [expires_in] => 600 
            [re_expires_in] => 660 
            [refresh_token] => composeB106b7cb440c141918ecc0a4114f00E93 
            [user_id] => 2088102173187930 
        ) 
        [sign] => h7FgXXr0bA5E5noSpNy9R3/zUZ9ZN40rIeSqSoXRAz0v8Bqz8igGWvyb996I2EhCvajP88Z9WCdhDJ+Wipdz2//fnodQNT8JmUo7hXAaKSwOC+4ku/B5nrr7/XpC8LYhSzyT6P6JJFW5mQQMQKuE+5QOPtQnrEEZ4QSr3nirSwI= 
    )
    stdClass Object ( 
        [error_response] => stdClass Object ( 
            [code] => 40002 
            [msg] => Invalid Arguments 
            [sub_code] => isv.code-invalid 
            [sub_msg] => 授权码code无效 
        ) 
        [sign] => aGqSkdOsKFu60UECKKnhYYehjgJcsoYTnYcvJWRoH8SwPdNViz31ecB+D8BdNqEZ49ZqvemvINVvfVLT1V0fZHcxtrCn+UV5uDZPb2VtHlQ4fPGxRFEPi2CobGImYojeHv+28124eaSYjQe9ZxzWd/Edp6BlOiVpEAZsKfm52AI= 
        )
     */
    public function receiveCode()
    {
        $code=input("code");
        $request = new \AlipaySystemOauthTokenRequest();
        $request->setCode($code);
        $request->setGrantType("authorization_code");
        $response = $this->client->execute($request);
        print_r($response);
    }
    /*
    stdClass Object ( 
        [alipay_user_info_share_response] => stdClass Object ( 
            [code] => 10000 
            [msg] => Success 
            [gender] => m 
            [is_certified] => T 
            [is_student_certified] => F 
            [user_id] => 2088102173187930 
            [user_status] => T 
            [user_type] => 2 
        ) 
        [sign] => feFIBAso/iXwHLnUwNuJuXJ32CH/P/hod+f1ekfZvB2duxK9u9T78YerzfDHB0VggWSuhHg/+C8akPqrjzuNeGxLMGZlefOngbPbJ9csn4BU5vsFxNqZSgFGWWTCi6le/wOasIhcZ5mTfmJFEV7JZrV+fHhHFkTx3Bkh3bnA7SI= 
    )
    stdClass Object ( 
        [alipay_user_info_share_response] => stdClass Object ( 
            [code] => 20001 
            [msg] => Insufficient Token Permissions 
            [sub_code] => aop.auth-token-time-out 
            [sub_msg] => 访问令牌已过期 
        ) 
        [sign] => xB1zty55KH8s7KWH9zKaF7fXNGFZTGU0ycBf2U63SLWEh/hYbNXeuSifoYjiHe2HZXMIBW0dAicPUU6nkMviEYpKx0coBd0qZ5c0uGNq95KxYcT4bvWBkUmPO0rzXt5ikKRQgF5pUsv+SqN2alBhne2rv+N5w1XWSRD0bRIEUlI= 
    )
    */
    public function userinfo()
    {
        $token=input("token");
        $request = new \AlipayUserInfoShareRequest();
        $response = $this->client->execute($request,$token);
        print_r($response);
    }
}
